using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_pages_ajax_poll : System.Web.UI.Page
{
    Common comm = new Common();
    public string id = "",sql="",vote="",act="",stl1="0",stl2="0",stl3="0",stl4="0",stl5="0";
    public DataTable dtt;
	public Boolean kt=false;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["actm"].ToString()))
        {
            act = comm.TextFormat(Request.QueryString["actm"].ToString());
        }
        if (!string.IsNullOrEmpty(Request.QueryString["idm"].ToString()))
        {
            id = comm.TextFormat(Request.QueryString["idm"].ToString());
        }
        if (id != "" && act == "view")
        {
            dtt = comm.getDataTable("select * from HeThong_danh_gia_doanh_nghiep where ma_ntd='" + id + "'");
            if(dtt.Rows.Count>0)
            {
				stl1=dtt.Rows[0]["traloi1"].ToString();
				stl2=dtt.Rows[0]["traloi2"].ToString();
				stl3=dtt.Rows[0]["traloi3"].ToString();
				stl4=dtt.Rows[0]["traloi4"].ToString();
				stl5=dtt.Rows[0]["traloi5"].ToString();
            }
        }
    }
    protected void btnVote_Click(object sender, EventArgs e)
    {
        try
        {
            if (id != "" && act == "vote")
            {
                string sTest = comm.execScalar("select ma_ntd from HeThong_danh_gia_doanh_nghiep where ma_ntd=" + id);
                if (traloi1.Checked) vote = "traloi1";
                if (traloi2.Checked) vote = "traloi2";
                if (traloi3.Checked) vote = "traloi3";
                if (traloi4.Checked) vote = "traloi4";
                if (traloi5.Checked) vote = "traloi5";

                if (!string.IsNullOrEmpty(sTest))//Da co danh gia danh cho doanh nghiep nay,ta update danh gia moi
                {
                    sql = "update HeThong_danh_gia_doanh_nghiep set " + vote + "=" + vote + "+1";
                }
                else
                {
                    sql = "Insert HeThong_danh_gia_doanh_nghiep(ma_ntd ," + vote + ") values(" + id + ",1)";
                }
                int i = comm.execNoneQuery(sql);
                Response.Redirect("ajax_poll.aspx?actm=view&idm=" + id);
            }
        }
        catch (Exception er)
        {
            sql = "loi";
        }
    }
}
